Fix compiler warnings and potential overflows in cecc-client and libcec#708
Open
heitbaum wants to merge 7 commits intoPulse-Eight:masterfrom
Open
Fix compiler warnings and potential overflows in cecc-client and libcec#708heitbaum wants to merge 7 commits intoPulse-Eight:masterfrom
heitbaum wants to merge 7 commits intoPulse-Eight:masterfrom
Conversation
strncpy does not guarantee null-termination when the source length meets or exceeds the destination size. comm and path are fixed 1024-byte buffers in cec_adapter, making snprintf the correct tool — it always null-terminates and handles truncation safely. Fixes -Wstringop-truncation warnings.
strDeviceName is copied into a fixed-size intermediate buffer and then into m_configuration.strDeviceName. snprintf always null-terminates, making the zero-initialisation of buf unnecessary. Fixes -Wstringop-truncation warnings.
The default branch left strLevel uninitialised, causing undefined behaviour if an unknown log level was passed. Fixes -Wmaybe-uninitialized warning.
…le_command buflen was computed but never used. The || dispatch chain's return value was discarded; wrapped in (void) cast to make the short-circuit-for-side-effects intent explicit. Fixes -Wunused-but-set-variable and -Wunused-value warnings.
g_strPort is only 50 bytes. In cec_process_command_line_arguments, argv strings are unbounded; in main, devices[0].comm is a 1024-byte buffer. Both strcpy calls risked overflow if the comm port name exceeded 49 characters. Replaced with snprintf bounded to sizeof(g_strPort).
sizeof(g_config.strDeviceName) keeps the bound tied to the struct definition rather than a hard-coded value.
Truncation into fixed-size destination buffers is intentional. GCC diagnostic pragmas suppress the warning at each call site.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a series of compiler warnings across cecc-client.c, AdapterFactory.cpp,
and CECClient.cpp.
issues were found when compiling on Ubuntu 26.04 with gcc-16